﻿// Parser.fs
//
// Copyright 2009 Sergey Mechtaev
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation.


#light

namespace SmartCPP.Core.Parser

open System.Text

module Parser =

    ///Translate Lexer lexemes to Parser lexemes
    let TransformLexerOutput (lexer:(Text.Lexing.LexBuffer<_>->Lexer.Tokens)) =
            let newlexer lexbuf =
                let oldlexeme = lexer lexbuf
                match oldlexeme with
                    | Lexer.Text s -> GeneratedParser.Text s
                    | Lexer.Define s -> GeneratedParser.Define s
                    | Lexer.Elif s -> GeneratedParser.Elif s
                    | Lexer.Else p -> GeneratedParser.Else p
                    | Lexer.Endif p -> GeneratedParser.Endif p
                    | Lexer.Eof -> GeneratedParser.Eof
                    | Lexer.If s -> GeneratedParser.If s
                    | Lexer.Ifdef s -> GeneratedParser.Ifdef s
                    | Lexer.Include s -> GeneratedParser.Include s                
            newlexer
            
    ///Get file presentation like tree of texts and directives
    let parse lexBuffer = (GeneratedParser.start (TransformLexerOutput Lexer.token) lexBuffer)